package lesson01;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

/**
 * @Auther: xiaofei
 * @Date: 2021/6/28 - 06 - 28 - 16:21
 * @Description: lesson01
 * @version: 1.0
 */
public class UDPSenderDemo01 {
    //这是一个main方法，是程序的入口：
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(8888);

        // 准备数据，控制台读取
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String data = reader.readLine();
            byte[] datas = data.getBytes();
            DatagramPacket packet = new DatagramPacket(datas,0,datas.length,new InetSocketAddress("localhost",6666));

            socket.send(packet);
            if(data.equals("bye")){
                break;
            }
        }
        socket.close();
    }
}
